import React, { useEffect, useRef } from 'react';

interface IProps {
  show: boolean;
}

const BackgroundMusic = (props: IProps) => {
  const { show } = props;
  const audioRef = useRef<HTMLAudioElement>(null);

  useEffect(() => {
    if (show) {
      audioRef.current?.play();
    }
  }, [show]);

  return <audio ref={audioRef} src="/audios/going-home.mp3" autoPlay loop></audio>;
};

export default BackgroundMusic;
